﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HidesaburoDotNET.Core.Detecctors
{
    public class SanshokuDetector : YakuDetector
    {
        public override Yaku CheckYaku(AgariTehai agariTehai)
        {
            int[] b = new int[5];
            for (int i = 0; i < agariTehai.Mentsu.Count; i++)
            {
                Mentsu m = agariTehai.Mentsu[i];
                if (m.Type == MentsuType.Syuntsu_A || m.Type == MentsuType.Syuntsu_M)
                {
                    b[i] = m[0].Number;
                }
            }
            bool Sanshoku = false;

            if (b[1] == b[2] && b[1] == b[3])
            {
                Sanshoku = true;
            }
            else if (b[1] == b[2] && b[1] == b[4])
            {
                Sanshoku = true;
            }
            else if (b[1] == b[3] && b[1] == b[4])
            {
                Sanshoku = true;
            }
            else if (b[2] == b[3] && b[2] == b[4])
            {
                Sanshoku = true;
            }
            else
            {
                Sanshoku = false;
            }

            if(Sanshoku)
            {
                if(agariTehai.Menzen)
                {
                    return new Yaku (2, "サンショクドウジュン");
                }
                else
                {
                    return new Yaku (1, "サンショクドウジュン");
                }
            }
            else
            {
                return new Yaku();
            }
        }
    }
}
